<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="70%" destroy-on-close @closed="$emit('closed')" :close-on-click-modal="false">
        <el-container>
			<el-header>
                <div class="right-panel-search">
                    <el-input v-model="search.end_price" placeholder="搜索单据编号/产品编码/产品名称" clearable></el-input>
                    <el-select v-model="search.pay_type" filterable placeholder="请选择业务状态">
                        <el-option label="是" :value="1"/>
                        <el-option label="否" :value="2"/>
                    </el-select>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="info" @click="refresh">重置</el-button>
                </div>
            </el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" @select-all="selectAll" @selection-change="selectionChange" :params="query" stripe remoteSort remoteFilter height="460" border>
					<el-table-column type="selection" width="50" align="center"></el-table-column>
                    <el-table-column label="单据编号" prop="production_code" align="center">
						<template #default="scope">
							<span style="color: #0099ff;cursor: pointer;">{{ scope.row.production_code }}</span>
						</template>
					</el-table-column>
					<el-table-column label="单据日期" prop="production_date" align="center"></el-table-column>
					<el-table-column label="计划开工日期" prop="plan_start" align="center"></el-table-column>
					<el-table-column label="计划完工日期" prop="plan_end" align="center"></el-table-column>
					<el-table-column label="业务状态" prop="status" align="center">
                        <template #default="scope">
							<el-tag v-if="scope.row.status == 0" type="danger">计划</el-tag>
							<el-tag v-if="scope.row.status == 1 && (scope.row.number != scope.row.ware_number)" type="primary">开工</el-tag>
							<el-tag v-if="scope.row.status == 1 && (scope.row.number == scope.row.ware_number)" type="success">完工</el-tag>
						</template>
                    </el-table-column>
					<el-table-column label="物料编码" prop="product.goods_code" align="center"></el-table-column>
					<el-table-column label="物料名称" prop="product.goods_name" align="center"></el-table-column>
					<el-table-column label="规格型号" prop="product.goods_spec" align="center"></el-table-column>
					<el-table-column label="计划生产数量" prop="number" align="center"></el-table-column>
					<el-table-column label="入库数量" prop="ware_number" align="center"></el-table-column>
					<el-table-column label="工序进度条" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="备注" prop="remark" align="center"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="back">确 定</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择生产加工单',
			},
			visible: false,
			isSaveing: false,
			apiObj: this.$API.production.production.list,
            selection:[],
            search: {
				keywords: null,
                position_id:null,
                class_id:null,
                title_keywords:null
			},
            index: ""
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        selectAll() {
			this.$message.error("只能单选！")
			this.$refs.table.clearSelection()
		},
        selectionChange(selection) {
			if(selection.length > 1){
				const del_row = selection.shift()
				this.$refs.table.toggleRowSelection(del_row,false) //设置这一行取消选中
			}
			this.selection = selection;
		},
        back(){
            this.$emit('success', this.selection,this.mode,this.index)
            this.visible = false;
        },
        setData(data) {
            this.index = data
		},
	}
}
</script>

<style></style>
